package cn.tedu.weibo1.Controller;

import cn.tedu.weibo1.mapper.CommentMapper;
import cn.tedu.weibo1.pojo.dto.CommentDTO;
import cn.tedu.weibo1.pojo.dto.CommentDTOs;
import cn.tedu.weibo1.pojo.entity.Comment;
import cn.tedu.weibo1.pojo.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class CommentController {
    @Autowired(required = false)
    CommentMapper mapper;
    @RequestMapping("/comment/insert")
    public int insert(@RequestBody CommentDTO comment, HttpSession session){
        Comment comment1=new Comment();
        UserVO userVO=(UserVO) session.getAttribute("user");
        if(userVO==null){
            return 2;
        }
        BeanUtils.copyProperties(comment,comment1);
        comment1.setUserId(userVO.getId());
        mapper.insert(comment1);
        return 1;
    }
    @RequestMapping("/comment/selects")
    public List<CommentDTOs> selects(int id){
        return mapper.selects(id);
    }
}
